package Test_0817.ioperations;

import Test_0817.book.Book;
import Test_0817.book.BookShelf;

import java.util.Scanner;

public class ReturnOperation implements Ioperation{
    @Override
    public void work(BookShelf bookShelf) {
        System.out.println("归还图书");
        System.out.println("请输入该书名：");
        Scanner scanner=new Scanner(System.in);
        String returnName=scanner.nextLine();
        int ret=bookShelf.getUseSize();
        for (int i=0; i < ret; i++) {
            Book book=bookShelf.getBook(i);
            //判断该图书书架是否已经有该本书：
            //如果有
            if (returnName.equals(book.getName())){
                //如果该书已被借阅
                if(book.isBorrowed()){
                    //那么归还
                    book.setBorrowed(false);
                    System.out.println("归还成功！！！");
                    return;
                }else{
                    System.out.println("不好意思该书未被借阅，归还失败~");
                    return;
                }
            }
            System.out.println("不好意思，图书中没有该本图书信息~");
        }
    }
}
